package news.paper.tintuc.tinnong.docbao.doctin.controller;

import news.paper.tintuc.tinnong.docbao.doctin.AppController;

import org.json.JSONObject;

import com.android.volley.Request.Method;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;

public class Controller {

	public static final int perpage = 10;
	private final String link_type = "http://dataprovider.touch.baomoi.com/json/home.aspx?toppicks=0&pictures=0&showzonesources=1&zonesources=2[specialzone]:3[specialzone]:119[zone]:58[zone]:45[zone]:55[zone]:121[zone]:52[zone]:53[zone]&localNews=0&adminArea=H%C3%A0%20N%E1%BB%99i&subAdminArea=H%C3%A0%20N%E1%BB%99i&v=2";
	private final String link_list = "http://dataprovider.touch.baomoi.com/json/ArticleList.aspx?listType=";
	private final String link_detail = "http://dataprovider.touch.baomoi.com/json/Article.aspx?articleId=";
	public void getListType(final RequestListener listener) {
		listener.begin();
		JsonObjectRequest jsonObjReq = new JsonObjectRequest(Method.GET,
				link_type, null, new Response.Listener<JSONObject>() {

					@Override
					public void onResponse(JSONObject response) {
						listener.success(response);
					}
				}, new Response.ErrorListener() {

					@Override
					public void onErrorResponse(VolleyError error) {
						listener.fail(error.getMessage());

					}
				}) {
		};
		AppController.getInstance().addToRequestQueue(jsonObjReq);
	}

	public void sengcmid(String SenderID_,String IMEI_,final RequestListener listener) {
		listener.begin();
		JsonObjectRequest jsonObjReq = new JsonObjectRequest(Method.GET,
				link_type, null, new Response.Listener<JSONObject>() {

					@Override
					public void onResponse(JSONObject response) {
						listener.success(response);

					}
				}, new Response.ErrorListener() {

					@Override
					public void onErrorResponse(VolleyError error) {
						listener.fail(error.getMessage());

					}
				}) {
		};
		AppController.getInstance().addToRequestQueue(jsonObjReq);
	}
	
	
	public void getListNews(String listType, String listId, String start,
			String count, final RequestListener listener) {
		listener.begin();
		JsonObjectRequest jsonObjReq = new JsonObjectRequest(Method.GET,
				link_list + listType + "&listId=" + listId + "&start=" + start
						+ "&count=" + count, null,
				new Response.Listener<JSONObject>() {

					@Override
					public void onResponse(JSONObject response) {
						listener.success(response);

					}
				}, new Response.ErrorListener() {

					@Override
					public void onErrorResponse(VolleyError error) {
						listener.fail(error.getMessage());

					}
				}) {
		};
		AppController.getInstance().addToRequestQueue(jsonObjReq);
	}

	public void getNewsDetail(String articleId, String listType, String listId,
			final RequestListener listener) {
		listener.begin();
		JsonObjectRequest jsonObjReq = new JsonObjectRequest(Method.GET,
				link_detail + articleId + "&listType=" + listType + "&listId="
						+ listId + "&articleType=full", null,
				new Response.Listener<JSONObject>() {

					@Override
					public void onResponse(JSONObject response) {
						listener.success(response);

					}
				}, new Response.ErrorListener() {

					@Override
					public void onErrorResponse(VolleyError error) {
						listener.fail(error.getMessage());

					}
				}) {
		};
		AppController.getInstance().addToRequestQueue(jsonObjReq);
	}
}
